﻿using IOP.SgrA.SilkNet.Vulkan.Scripted;
using IOP.SgrA.SilkNet.Vulkan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IOP.SgrA.GLSL;
using Silk.NET.Vulkan;

namespace VkSample113
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class SeaVert : GLSLVert
    {
        [PushConstant(64, 0)]
        public ConstantVals myConstantVals { get; set; }
        [UniformBuffer(0, 0, DescriptorSetTarget.RenderObject)]
        public SeaVals myBufferVals { get; set; }
        [VertInput(0, Format.R32G32B32Sfloat)]
        public vec3 pos { get; set; }
        [VertInput(1, Format.R32G32Sfloat)]
        public vec2 inTexCoor { get; set; }

        [ShaderOutput(0)]
        public vec2 outTexCoor { get; set; }

        public override void main()
        {
            //计算X向角度          		
            float angleSpanH = 4.0f * 3.14159265f;//横向角度总跨度，用于进行X距离与角度的换算
            float startX = -myBufferVals.uWidthSpan / 2.0f;//起始X坐标(即最左侧顶点的X坐标)
                                                          //根据横向角度总跨度、横向长度总跨度及当前点X坐标折算出当前顶点X坐标对应的角度
            float currAngleH = myBufferVals.uStartAngle + ((pos.x - startX) / myBufferVals.uWidthSpan) * angleSpanH;

            //计算出随Y向发展起始角度的扰动值
            float angleSpanZ = 4.0f * 3.14159265f;//纵向角度总跨度，用于进行Y距离与角度的换算 
            float uHeightSpan = 0.75f * myBufferVals.uWidthSpan;//纵向长度总跨度
            float startY = -uHeightSpan / 2.0f;//起始Y坐标(即最上侧顶点的Y坐标)
                                              //根据纵向角度总跨度、纵向长度总跨度及当前点Y坐标折算出当前顶点Y坐标对应的角度
            float currAngleZ = ((pos.y - startY) / uHeightSpan) * angleSpanZ;
            //计算斜向波浪
            float tzH = sin(currAngleH - currAngleZ) * 0.3f;//通过正弦函数求出当前点的Z坐标   

            outTexCoor = inTexCoor;
            gl_Position = myConstantVals.mvp * new vec4(pos.x, pos.y, tzH, 1.0f);
        }
    }

    public struct SeaVals
    {
        public float uWidthSpan;
        public float uStartAngle;
    }
}
